<html>
<head>
<meta charset="UTF-8">
<title>批次任务配置新增</title>
	<link id="easyuiTheme"  href="../../static/easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css"/>
	<link href="../../static/easyui/themes/icon.css" rel="stylesheet" type="text/css"/>
	<link href="../../static/css/esaas-easyui-add.css" rel="stylesheet" type="text/css"/>
	<script src="../../static/easyui/jquery.min.js" type="text/javascript"></script>
	<script src="../../static/easyui/jquery.cookie.js" type="text/javascript"></script>
	<script src="../../static/easyui/ui-theme.js" type="text/javascript"></script>
	<script src="../../static/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../static/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.util.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.jquery.ajax.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.easyui.util.js" type="text/javascript"></script>
	<script src="../../ffres/dict/all.js" type="text/javascript"></script>
	<a href="" target="_blank" id="commonLink" name="commonLink"></a>
</head>
<body class="easyui-layout">
	<form id="ff" method="post">
		<table class="esaas-info-add-table" style="margin-top: 15px;">
			<tr>
				<td width="15%" align="right">任务编号：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="taskId" data-options="required:true"
					style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">任务名称：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="taskName" data-options="required:true"
					style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right">前一任务编号：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="previousTaskId" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">应用插件ID：</td>
				<td width="35%"><input class="easyui-textbox" type="text" buttonText="选择应用插件"
									   id="pluginId" name="pluginId" data-options="required:true"
									   style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right">插件配置数据标识：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="pluginParaFlag" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">任务最大重复调起次数：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
									   name="maxRunCount" data-options="required:false"
									   style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right"><span id="cycleIntevalLabel">轮询间隔(秒)：</span></td>
				<td width="35%"><input class="easyui-textbox" type="text" id="cycleInteval"
					name="cycleInteval" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right"><span id="maxWaitTimeLabel">最长等待时间：</span></td>
				<td width="35%"><input class="easyui-textbox" type="text" id="maxWaitTime"
					name="maxWaitTime" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right"><span id="taskCycleTypeLabel">任务周期类型：</span></td>
				<td width="35%"><select class="easyui-combobox" 
					id="taskCycleType" name="taskCycleType"
					style="width: 100%; height: 25px;"
					data-options="required:false,editable:false,valueField:'enname',textField:'cnname',data:BAT_CYCLE_TYPE">
				</select></td>
				<td width="15%" align="right"><span id="taskCronValueLabel">任务定时周期：</span></td>
				<td width="35%"><input class="easyui-textbox" type="text"
					id="taskCronValue" name="taskCronValue" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right">任务延时执行时间(秒)：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
									   name="taskDelayTime" data-options="required:false"
									   style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">任务重复调起时间间隔(秒)：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="againRunSpace" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right">任务运行超时时间(秒)：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
									   name="taskTimeoutTime" data-options="required:false"
									   style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">任务预计执行时间(秒)：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="taskEstimateTime" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right">任务使用状态：</td>
				<td width="35%"><select class="easyui-combobox"
					id="taskUseState" name="taskUseState"
					style="width: 100%; height: 25px;"
					data-options="required:true,editable:false,valueField:'enname',textField:'cnname',data:BAT_TASK_USE_STATE">
				</select></td>
				<td width="15%" align="right">任务使用场景：</td>
				<td width="35%"><select class="easyui-combobox"
										id="taskUseArea" name="taskUseArea"
										style="width: 100%; height: 25px;"
										data-options="required:true,editable:false,valueField:'enname',textField:'cnname',data:BAT_TASK_USE_AREA">
				</select></td>
			</tr>
			<tr>
				<td width="15%" align="right">任务失败跳过策略：</td>
				<td width="35%"><select class="easyui-combobox"
										id="taskSkipTactic" name="taskSkipTactic"
										style="width: 100%; height: 25px;"
										data-options="required:true,editable:false,valueField:'enname',textField:'cnname',data:BAT_TASK_SKIP_TACTIC">
				</select></td>
				<td width="15%" align="right">任务执行类型：</td>
				<td width="35%"><select class="easyui-combobox"
										id="taskRunType" name="taskRunType"
										style="width: 100%; height: 25px;"
										data-options="required:false,editable:false,valueField:'enname',textField:'cnname',data:BAT_TASK_RUN_TYPE, onSelect: doTaskRunTypeSelect">
				</select></td>
			</tr>
			<tr>
				<td width="15%" align="right">任务数据源：</td>
				<td width="35%"><input class="easyui-textbox" type="text" buttonText="选择数据源"
					id="subsDsCode" name="subsDsCode" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right">备注：</td>
				<td width="85%" colspan="3"><input class="easyui-textbox" type="text"
					name="remark" data-options="required:false, multiline: true"
					style="width: 100%; height: 50px;"></input></td>
			</tr>
			<tr hidden="true">
				<td width="15%" align="right">所属批次：</td>
				<td width="35%"><input class="easyui-textbox" type="text" id="batchId"
									   name="batchId" data-options="required:true, disabled: true"
									   style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">阶段编号：</td>
				<td width="35%"><input class="easyui-textbox" type="text" hidden
									   id="stageId" name="stageId" data-options="required:true"
									   style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">执行场所编号：</td>
				<td width="35%"><input class="easyui-textbox" type="text" hidden
									   id="localeId" name="localeId" data-options="required:true"
									   style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr hidden="true">
				<td width="15%" align="right">应用插件类型：</td>
				<td width="35%"><select class="easyui-combobox"
										id="pluginType" name="pluginType"
										style="width: 100%; height: 25px;"
										data-options="required:false,editable:false,valueField:'enname',textField:'cnname',data:BAT_PLUGIN_TYPE">
				</select></td>
				<td width="15%" align="right">插件配置数据来源方式：</td>
				<td width="35%"><select class="easyui-combobox"
										id="pluginSourceType" name="pluginSourceType"
										style="width: 100%; height: 25px;"
										data-options="required:true,editable:false,valueField:'enname',textField:'cnname',data:BAT_PLUGIN_SOURCE_TYPE">
				</select></td>
			</tr>
			<tr hidden="true">
				<td width="15%" align="right">任务优先级：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
									   name="taskPri" data-options="required:false"
									   style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">任务运行超时策略：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
									   name="taskTimeoutTactic" data-options="required:false"
									   style="width: 100%; height: 25px;"></input></td>
			</tr>
		</table>
	</form>
	<div class="esaas-info-buttons">
		<a href="javascript:void(0)" class="easyui-linkbutton " iconCls="icon-ok" onclick="submitForm()" style="width:90px">&nbsp;保&nbsp;存&nbsp;</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="closeForm()" style="width:90px">&nbsp;关&nbsp;闭&nbsp;</a>
	</div>
	<script>
		$(function() {
			//doTaskRunTypeSelect();
			addTitle("新增批次任务配置信息");
			doTaskRunTypeSelect(null);
			var params = JLEUtil.paramUrl2Obj(window.location.href);
			$("#batchId").textbox('setValue', params.batchId);
			$("#stageId").textbox('setValue', params.stageId);
			$("#localeId").textbox('setValue', params.stageId);
			$("#batchId").textbox('setText', params.batchId);
			$("#pluginSourceType").combobox('setValue', 1);
			$("#pluginType").combobox('setValue', 1);
			$("#taskRunType").combobox('setValue', 1);
			$("#taskSkipTactic").combobox('setValue', 2);
			$("#taskUseState").combobox('setValue', 0);
			$("#taskUseArea").combobox('setValue', 1);
			$("#pluginId").textbox({
				onClickButton:function (){
					JLEUtil.createModalWinCustomSize('', 'popPluginDefine.html');
				}
			});
			$("#subsDsCode").textbox({
				onClickButton:function (){
					JLEUtil.createModalWinCustomSize('', 'popSSubsDatasourceChoice.html?subsCode='+window.parent.subsCode);
				}
			});
		});

		function submitForm() {
			if (!$('#ff').form('validate'))
				return;
			var jsonData = $("#ff").serializeJson();
			$.restfulPostJson('../../api/bat/task/unit/config', jsonData, function(data) {
				window.parent.reloadList();
			});
		};

		function choosePlugin(pluginId){
			$("#pluginId").textbox('setValue', pluginId);
		}

		function chooseSSubsDatasource(subsDsCode){
			$("#subsDsCode").textbox('setValue', subsDsCode);
		}
		
		function doTaskRunTypeSelect(data) {
			if(data && data.enname == '2') {
				showCycleInterval(true);
				showTaskCycle(false);
			} else if(data && data.enname == '3') {
				showCycleInterval(false);
				showTaskCycle(true);
			} else {
				showCycleInterval(false);
				showTaskCycle(false);
			}
		}

		function showCycleInterval(isShow) {
			if(isShow) {
				$("#cycleIntevalLabel").show();
				$("#cycleInteval").next().show();
				$("#maxWaitTimeLabel").show();
				$("#maxWaitTime").next().show();
			} else {
				$("#cycleIntevalLabel").hide();
				$("#cycleInteval").next().hide();
				$("#maxWaitTimeLabel").hide();
				$("#maxWaitTime").next().hide();

				$("#cycleInteval").textbox('setValue', '');
				$("#maxWaitTime").textbox("setValue", '');
			}
		}

		function showTaskCycle(isShow) {
			if(isShow) {
				$("#taskCycleTypeLabel").show();
				$("#taskCycleType").next().show();
				$("#taskCronValueLabel").show();
				$("#taskCronValue").next().show();
			} else {
				$("#taskCycleTypeLabel").hide();
				$("#taskCycleType").next().hide();
				$("#taskCronValueLabel").hide();
				$("#taskCronValue").next().hide();

				$("#taskCycleType").textbox("setValue", '');
				$("#taskCronValue").textbox("setValue", '');
			}
		}
		
		function closeForm() {
			window.parent.JLEUtil.closewin();
		}
	</script>
</body>
</html>